//
//  JWMovieCell.m
//  JWMovie
//
//  Created by Jorn.Wu on 15/7/18.
//  Copyright (c) 2015年 Jorn.Wu. All rights reserved.
//

#import "JWNewsCell.h"
#import "JWnewsModel.h"
#import "constant.h"
#import "UIImageView+WebCache.h"

@interface JWNewsCell()

@property (nonatomic, strong) UIImageView *image;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *summary;
@property (nonatomic, assign) int type;
@property (nonatomic, strong) UIImageView *markImage;//是否有截图的标志

@end
@implementation JWNewsCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        self.backgroundColor = [UIColor clearColor];
        
        //      电影图片
        
        UIImageView *moviewImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        moviewImage.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:moviewImage];
        _image = moviewImage;
        
        //      电影名
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
//        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont systemFontOfSize:17];
        [self.contentView addSubview:titleLabel];
        _title = titleLabel;
//        _title.backgroundColor = [UIColor grayColor];
        
        //      电影概述
        
        UILabel *summaryLabel = [[UILabel alloc] initWithFrame:CGRectZero];
//        summaryLabel.textAlignment = NSTextAlignmentCenter;
        summaryLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:summaryLabel];
        _summary = summaryLabel;
        _summary.textColor = [UIColor orangeColor];
//        _summary.backgroundColor = [UIColor grayColor];
        
        //      截图标识
        
        UIImageView *markImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:markImage];
        _markImage = markImage;
 
    }
    return self;
}

- (void)setNewsModel:(JWnewsModel *)newsModel{
    _newsModel = newsModel;
    
    //      电影图片
    
    NSString *urlStr = _newsModel.image;
//    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
//    UIImage *image = [UIImage imageWithData:imageData];
//    self.image.image = image;
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:urlStr]];
    
    //      电影名
    
    self.title.text = _newsModel.title;
    
    //      电影概述
    
    self.summary.text = _newsModel.summary;
    
    //      截图标识
    
    self.type = _newsModel.type;

    if (_type == 1) {
        
        UIImage *img = [UIImage imageNamed:@"sctpxw@2x"];
        self.markImage.image = img;
    }else if (_type == 2) {
        
        UIImage *img = [UIImage imageNamed:@"scspxw@2x"];
        self.markImage.image = img;
    }
    else {
        self.markImage.image = nil;
//        self.markImage.hidden = YES;
    }
   
}

+ (instancetype)newsCellWithTableView:(UITableView *)table{
    static NSString *ID = @"newsCell";
    JWNewsCell *cell = [table dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    return cell;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.image.frame = CGRectMake(5, (JWNewsCellHeight - 60) * 0.5, 60, 60);
    
    self.title.frame = CGRectMake(60 + 10, 10, 250, 20);
    
    self.summary.frame = CGRectMake(95, JWNewsCellHeight - 20 - 10, 200, 20);
    
    self.markImage.frame = CGRectMake(60 + 10, JWNewsCellHeight - 17 - 10, 20, 17);
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
